package com.catosist.run.business.gestormarca;

import com.catosist.run.dataaccess.domain.MarcasDao;
import com.catosist.run.dataaccess.model.MarcasVO;
import com.catosist.run.dataaccess.model.VehiculoVO;
import com.catosist.run.services.MarcasDTO;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author Carlos
 */
public class GestorMarcasImpl implements GestorMarcas {

    public GestorMarcasImpl() {
    }

    @Override
    public List<MarcasDTO> getAll() {
        if (marcasVOs == null) {
            marcasVOs = marcasDao.getAll();
        }
        List<MarcasDTO> marcasDTOs = new LinkedList<MarcasDTO>();
        for (Iterator<MarcasVO> it = marcasVOs.iterator(); it.hasNext();) {
            MarcasVO marcasVO = it.next();
            marcasDTOs.add(new MarcasDTO(marcasVO.getId(),
                    marcasVO.getNombre()));
        }
        return marcasDTOs;
    }


    public MarcasDTO get(int indice) {
        MarcasVO marcasVO = getVOatIndex(indice);
        return new MarcasDTO(marcasVO.getId(),
                marcasVO.getNombre());
    }


    public MarcasVO getVOatIndex(int indice) {
        return marcasVOs.get(indice);
    }


    public MarcasDao getMarcasDao() {
        return marcasDao; 
    }


    public void setMarcasDao(MarcasDao marcasDao) {
        this.marcasDao = marcasDao;
    }

    @Override
    public void deleteById(int Id) {
        MarcasVO marcasVO = new MarcasVO();
        marcasVO.setId(Id);
        marcasDao.deleteById(Id);
    }

    @Override
    public void saveOrUpdate(MarcasDTO o) {

        MarcasVO marcasVo = new MarcasVO();

        if (o.getId() > 0) {
            marcasVo.setId(o.getId());
        }

        marcasVo.setNombre(o.getNombre());

        VehiculoVO vehiculoVO = new VehiculoVO();
        vehiculoVO.setId(o.getVehiculoId());
       
    }

    @Override
    public int getIdAtIndex(int indice) {
        return this.marcasVOs.get(indice).getId();
    }

    private MarcasVO getByIndice(int indice) {
        return this.marcasVOs.get(indice);
    }

    @Override
    public MarcasDTO getById(int voId) {
        return null;
    }

    @Override
    public MarcasDTO getByIndex(int indice) {
        MarcasVO marcasVO = this.marcasVOs.get(indice);
        MarcasDTO tmp = new MarcasDTO(marcasVO.getId(), marcasVO.getNombre());
        return tmp;
    }

    private List<MarcasVO> marcasVOs;
    private MarcasDao marcasDao ;

    @Override
    public void updateListVo() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public int getIndexOf(int voId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void deleteByIndex(int index) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
